<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/13
 * Time: 16:48
 */
include "../classes/logincheck.php";
include '../classes/conn.php';
if(islogin()!='teacher_login'){
    die('error');
}
$sub_nums=$_POST['sub_nums'];
$sub_names=$_POST['sub_names'];
$sub_names_new=$_POST['sub_names_new'];
$sub_nums_new=$_POST['sub_nums_new'];
$class_num=$_POST['class_num'];
$sec_num=$_POST['sec_num'];
for($i=0;$i<count($sub_nums);$i++){
    if($sub_nums[$i]==$sub_nums_new[$i]){
        $query1="update subsection set num='{$sub_nums_new[$i]}',name='{$sub_names_new[$i]}' where num='{$sub_nums[$i]}' 
and class='{$class_num}' and teacher='{$_SESSION['t_num']}' and section ='{$sec_num}'";

        mysql_query($query1);
    }
    else{
        $query2="select num from subsection where num='{$sub_nums_new[$i]}' and class='{$class_num}' and teacher='{$_SESSION['t_num']}'and section ='{$sec_num}'";
        $res2=mysql_query($query2);
        if(mysql_num_rows($res2)>=1){
            echo 'sub_exist';
        }
        else {
            $query1 = "update subsection set num='{$sub_nums_new[$i]}',name='{$sub_names_new[$i]}' where num='{$sub_nums[$i]}' and class='{$class_num}' 
and teacher='{$_SESSION['t_num']}'and section ='{$sec_num}'";
            mysql_query($query1);
        }

    }
}